﻿CREATE TABLE [dbo].[Repairs] (
    [Id]             INT            IDENTITY (1, 1) NOT NULL,
    [WordOrderId]    NVARCHAR (50)  NOT NULL,
    [CompId]         NVARCHAR (50)  NOT NULL,
    [ArticleId]      INT            NOT NULL,
    [RepEmp]         INT            NULL,
    [FinishTime]     DATETIME       NULL,
    [StatusId]       INT            CONSTRAINT [D_dbo_Repairs_1] DEFAULT ((1)) NOT NULL,
    [ApplyEmp]       INT            NOT NULL,
    [ApplyTime]      DATETIME       NOT NULL,
    [Phone]          NVARCHAR (50)  NULL,
    [Email]          NVARCHAR (50)  NULL,
    [ApplyAddres]    NVARCHAR (50)  NOT NULL,
    [WhoEmpName]     INT            NULL,
    [Evaluate]       NVARCHAR (500) NULL,
    [score]          INT            NULL,
    [TroubleDesc]    NVARCHAR (500) NULL,
    [SolutionDesc]   NVARCHAR (500) NULL,
    [AsignTime]      DATETIME       NULL,
    [LastUpdateTime] DATETIME       NULL,
    CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED ([Id] ASC) WITH (FILLFACTOR = 100)
);












GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'报修人员评价', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Repairs', @level2type = N'COLUMN', @level2name = N'Evaluate';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'故障描述', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Repairs', @level2type = N'COLUMN', @level2name = N'TroubleDesc';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'故障原因及解决方案描述', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Repairs', @level2type = N'COLUMN', @level2name = N'SolutionDesc';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'报修人员评分', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Repairs', @level2type = N'COLUMN', @level2name = N'score';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'受理时间', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Repairs', @level2type = N'COLUMN', @level2name = N'AsignTime';


GO
create trigger tgr_repairs_update
on repairs
    for update
as
declare @workorderid nvarchar(50)
            select @workorderid =  WordOrderId from inserted;
           update Repairs set LastUpdateTime = getdate() where WordOrderId=@workorderid
GO
create trigger tgr_repairs_insert
on repairs 
  for insert
  as 
  declare @workorderid nvarchar(50)
            select @workorderid =  WordOrderId from inserted;
           update Repairs set LastUpdateTime = getdate() where WordOrderId=@workorderid
GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'最后更新时间', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Repairs', @level2type = N'COLUMN', @level2name = N'LastUpdateTime';

